interface CalcItf {
  calc(i: number, j: number): number;
}

class Npc1 implements CalcItf {
  calc(i: number, j: number): number {
    return i + j;
  }
}

class Npc2 implements CalcItf {
  calc(i: number, j: number): number {
    return i - j;
  }
}

export class Person {
  // 代理中间
  delegate: CalcItf;

  getNum(i: number, j: number): number {
    // 通过代理来计算
    return this.delegate.calc(i, j);
  }
}

let p = new Person();
// 设置 npc1 代理计算
p.delegate = new Npc1();
let res = p.getNum(10, 1);

// 设置 npc2 代理计算
p.delegate = new Npc2();
let res2 = p.getNum(1, 5);

console.log(res, res2);
